<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>websocket</title>
  <link href="/css/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
  <script src="/js/jquery-1.11.2.min.js"></script>
  <script src="/js/jquery-ui.min.js"></script>
    <script src="/sockjs.min.js"></script>
    <script src="/stomp.min.js"></script>
    <script>
        var stompClient = null;
        var subscription = null;
        $(function () {
            var ws = new SockJS("/websocket-address");
            stompClient = Stomp.over(ws);
            stompClient.heartbeat.b
            stompClient.connect({'client-id': 'my-client'},function () {
                console.log('connect success');
            },function(){
                console.log('connect fail');
            });


            $("#btn-send").click(function () {
                if(subscription != null){subscription.unsubscribe();}
                subscription = stompClient.subscribe("/topic/boardcast", function(){});
                stompClient.send("/app/boardcast",{},"请求广播");
            });
            $("#btn-send2").click(function () {
                if(subscription != null){subscription.unsubscribe();}
                subscription = stompClient.subscribe("/queue/topic/precise", function(){});
                stompClient.send("/app/precise",{},"请求精准投送");
            });
            // 请求动态广播
            $("#btn-send3").click(function () {
                if(subscription != null){subscription.unsubscribe();}
                subscription = stompClient.subscribe("/topic", function(){});
            });
            // 请求精准投送
            $("#btn-send4").click(function () {
                if(subscription != null){subscription.unsubscribe();}
                subscription = stompClient.subscribe("/queue/abc/message", function(){});
            });
        });
    </script>
<body>
<h1>spring-websocket-stomp</h1>
<button id="btn-send">广播消息</button>
<button id="btn-send2">精准投送消息</button>
<button id="btn-send3">动态广播</button>
<button id="btn-send4">动态精准投送</button>
</body>
</html>
